//定义过滤器
template.defaults.imports.len10 = function (value) {
    return value.substr(0, 10) + '...';
};

template.defaults.imports.dateFormat = function (value) {
    return moment(value).format('YYYY-MM-DD HH:mm:ss')
};


//获取数据
$.get('api/index', function (res) {
    //接收数据
    if (res.status == 200) {
        const {
            cates,
            image_news,
            new_news,
            hot_news
        } = res.data
        //console.log(new_news);
        //加载模板引擎
        //分类
        let cate_html = template('cates', {
            cates
        })
        $('#nav ul').html(cate_html)
        //图片新闻
        image_news.forEach(element => {
            element.img_url = "http://127.0.0.1:8080" + element.img_url;
        });
        let image_news_html = template('img_news', {
            image_news
        })
        $('#main1 ul').html(image_news_html)

        //最新新闻
        let new_news_html = template('new_news', {
            new_news
        })
        $(".new_news").html(new_news_html)

        //最热新闻
        let hot_news_html = template('hot_news', {
            hot_news
        })
        $(".hot_news").html(hot_news_html);

    }
})

